// 数据处理 Web Worker
self.onmessage = function (e) {
  const { type, data, viewport } = e.data;

  if (type === "process") {
    // 处理数据并返回可视区域内的点
    const processedData = processData(data, viewport);
    self.postMessage(processedData);
  }
};

// 过滤可视区域内的点
function processData(data, viewport) {
  if (!viewport) return data;

  const { left, right, top, bottom } = viewport;
  const visiblePoints = [];

  for (const point of data) {
    // 经纬度转像素坐标 (简化示例)
    const x = ((point.lng - 116.1574) / 0.65) * 1000;
    const y = ((39.6542 - point.lat) / 0.65) * 1000;

    // 检查是否在视口内
    if (x >= left && x <= right && y >= top && y <= bottom) {
      visiblePoints.push(point);
    }
  }
  return visiblePoints;
}
